package org.example.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.pojo.DataStatisticsVo;
import org.example.pojo.EmployeeMonthVo;
import org.example.pojo.JoinJobVo;
import org.example.pojo.OutJobVo;
import org.example.service.DataStatisticsService;
import org.example.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * 数据统计
 *
 * @author Administrator
 * @date 2022/09/01
 */
@Controller
@RequestMapping("/dataStatistics")
@Api(tags = "数据统计")
public class DataStatisticsController {

    @Autowired
    private DataStatisticsService dataStatisticsService;

    /**
     * 综合数据统计
     *
     * @return {@link ResponseData}
     */
    @GetMapping("/comprehensiveDataStatistics")
    @ResponseBody
    @ApiOperation("综合数据统计")
    public ResponseData comprehensiveDataStatistics(){
        //部门数量
        int deptCount = dataStatisticsService.selectDepartmentCount();
        //员工数量
        int empCount = dataStatisticsService.selectEmployeeCount();
        //角色数量
        int roleCount = dataStatisticsService.selectRoleCount();
        //管理员数量
        int managerCount = dataStatisticsService.selectManagerCount();
        //人才数量
        int talentsCount = dataStatisticsService.selectTalentsCount();
        //数量放入到集合中
        List<DataStatisticsVo> dataStatisticsList = new ArrayList<>();
        dataStatisticsList.add(new DataStatisticsVo(deptCount,"所有部门"));
        dataStatisticsList.add(new DataStatisticsVo(empCount,"所有员工"));
        dataStatisticsList.add(new DataStatisticsVo(roleCount,"全部角色"));
        dataStatisticsList.add(new DataStatisticsVo(managerCount,"全部管理员"));
        dataStatisticsList.add(new DataStatisticsVo(talentsCount,"人才储备库"));
//        Map<String,Object> map = new HashMap<>();
//        map.put("所有部门",deptCount);
//        map.put("所有员工",empCount);
//        map.put("全部角色",roleCount);
//        map.put("全部管理员",managerCount);
//        map.put("人才储备库",talentsCount);
        //将dataStatisticsList封装到ResponseData中
        ResponseData responseData = new ResponseData();
        responseData.setData(dataStatisticsList);
        return responseData;
    }

    /**
     * 人才储备统计
     *
     * @return {@link ResponseData}
     */
    @GetMapping("/talentReserveStatistics")
    @ResponseBody
    @ApiOperation("人才储备统计")
    public ResponseData talentReserveStatistics(){
        //人才状态数量
        List<DataStatisticsVo> dataStatistics = dataStatisticsService.selectTalentsStatistics();
        //将dataStatistics封装到ResponseData中
        ResponseData responseData = new ResponseData();
        responseData.setData(dataStatistics);

        return responseData;
    }

    /**
     * 部门员工统计
     *
     * @return {@link ResponseData}
     */
    @GetMapping("/departmentEmployeeStatistics")
    @ResponseBody
    @ApiOperation("部门员工统计")
    public ResponseData departmentEmployeeStatistics(){
        //部门员工
        List<DataStatisticsVo> list = dataStatisticsService.selectDepartmentEmployeeCount();
        //将map封装到ResponseData中
        ResponseData responseData = new ResponseData();
        responseData.setData(list);
        return responseData;
    }

    /**
     * 员工基本统计
     *
     * @return {@link ResponseData}
     */
    @GetMapping("/selectEmployeeGroupBy")
    @ResponseBody
    @ApiOperation("员工基本统计")
    public ResponseData selectEmployeeGroupBy(){
        //员工入职状态
        List<DataStatisticsVo> employeeGroupBy = dataStatisticsService.selectEmployeeGroupBy();
        //员工总数
        int employeeCount = dataStatisticsService.selectEmployeeCount();
        //员工白名单
        int employeeWhiteList = dataStatisticsService.selectEmployeeWhiteList();
        employeeGroupBy.add(new DataStatisticsVo(employeeCount,"全部员工"));
        employeeGroupBy.add(new DataStatisticsVo(employeeWhiteList,"白名单"));
        //将employeeGroupBy封装到ResponseData中
        ResponseData responseData = new ResponseData();
        responseData.setData(employeeGroupBy);
        return responseData;
    }

    /**
     * 员工月份统计
     *
     * @return {@link ResponseData}
     */
    @GetMapping("/employeeMonthlyStatistics")
    @ResponseBody
    @ApiOperation("员工月份统计")
    public ResponseData employeeMonthlyStatistics(){
        List<Integer> joins = new ArrayList<>();
        List<Integer> outs = new ArrayList<>();
        EmployeeMonthVo employeeMonthVo = new EmployeeMonthVo();
        //每月入职人数
        List<JoinJobVo> joinJobVos = dataStatisticsService.selectJoinJob();
        //每月入职人数放入集合中
        for (JoinJobVo j:joinJobVos
             ) {
            joins.add(j.getNumber());

        }
        employeeMonthVo.setJoinJob(joins);
//        System.out.println(joinJobVos);
//        employeeMonthVo.setJoinJob(joinJobVos);
        //每月离职人数
        List<OutJobVo> outJobVos = dataStatisticsService.selectOutJob();
        //每月离职人数放入集合中
        for (OutJobVo o:outJobVos
        ) {
            outs.add(o.getNumber());

        }
        employeeMonthVo.setOutJob(outs);
        //将employeeMonthVo封装到ResponseData中

        ResponseData responseData = new ResponseData();
        responseData.setData(employeeMonthVo);

        return responseData;
    }

    /**
     * 员工性别统计
     *
     * @return {@link ResponseData}
     */
    @GetMapping("/employeeSexStatistics")
    @ResponseBody
    @ApiOperation("员工性别统计")
    public ResponseData employeeSexStatistics(){
        //员工性别
        List<DataStatisticsVo> selectSex = dataStatisticsService.selectSex();
        ResponseData responseData = new ResponseData();
        //将selectSex封装到ResponseData中
        responseData.setData(selectSex);
        return  responseData;
    }

    /**
     * 在职状态统计
     *
     * @return {@link ResponseData}
     */
    @GetMapping("/jobStatusStatistics")
    @ResponseBody
    @ApiOperation("在职状态统计")
    public ResponseData  jobStatusStatistics(){
        List<DataStatisticsVo> jobStatus = dataStatisticsService.selectJobStatus();
        ResponseData responseData = new ResponseData();
        responseData.setData(jobStatus);
        return responseData;
    }

    /**
     * 黑白名单统计
     *
     * @return {@link ResponseData}
     */
    @GetMapping("/blackAndWhiteStatistics")
    @ResponseBody
    @ApiOperation("黑白名单统计")
    public ResponseData blackAndWhiteStatistics(){
        //白名单
        int employeeWhiteList = dataStatisticsService.selectEmployeeWhiteList();
        //黑名单
        int employeeBlackList = dataStatisticsService.selectEmployeeBlackList();
        //数据放入集合
        ArrayList<DataStatisticsVo> dataStatisticsVos = new ArrayList<>();
        dataStatisticsVos.add(new DataStatisticsVo(employeeBlackList,"黑名单员工"));
        dataStatisticsVos.add(new DataStatisticsVo(employeeWhiteList,"白名单员工"));
        //返回responseData
        ResponseData responseData = new ResponseData();
        responseData.setData(dataStatisticsVos);
        return responseData;
    }

}
